/*package cs294s.liveradar.service;

import java.io.ByteArrayOutputStream;
import java.nio.ByteBuffer;
import java.util.Hashtable;

import cs294s.liveradar.HomeScreen;
import android.app.Service;
import android.content.Intent;
import android.os.IBinder;

public class ConciergeService extends Service {

//XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
// constants
//XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
public static final String ServletUri = "http://" + AppUtils.EmulatorLocalhost + ":8080/Ping";

//XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
// static data/shared references, etc.
//XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
public static ServiceUpdateUIListener UI_UPDATE_LISTENER;
private static HomeScreen MAIN_ACTIVITY;

//XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
// data
//XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
private static Hashtable<String, Hashtable<DataKeys, String>> weatherData =
    new Hashtable<String, Hashtable<DataKeys, String>>();
private Timer timer = new Timer();
private static final long UPDATE_INTERVAL = 5000;

//XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
// hooks into other activities
//XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
public static void setMainActivity(HomeScreen activity) {
  MAIN_ACTIVITY = activity;
}

public static void setUpdateListener(ServiceUpdateUIListener l) {
  UI_UPDATE_LISTENER = l;
}

//XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
// lifecycle methods
//XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

public IBinder onBind(Intent intent) {
  return null;
}

@Override 
protected void onCreate() {
  super.onCreate();

  // init the service here
  _startService();

  //if (MAIN_ACTIVITY != null) AppUtils.showToastShort(MAIN_ACTIVITY, "MyService started");
}

@Override protected void onDestroy() {
  super.onDestroy();

  _shutdownService();

  //if (MAIN_ACTIVITY != null) AppUtils.showToastShort(MAIN_ACTIVITY, "MyService stopped");
}

//XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
// service business logic
//XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
private void _startService() {
  timer.scheduleAtFixedRate(
      new TimerTask() {
        public void run() {
          _getWeatherUpdate();
        }
      },
      0,
      UPDATE_INTERVAL);
  Log.i(getClass().getSimpleName(), "Timer started!!!");
}

//XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
// weather data that the service gets...
//XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
public static Hashtable<String, Hashtable<String, String>> DataFromServlet =
    new Hashtable<String, Hashtable<String, String>>();

private void _getWeatherUpdate() {
  // http post to the service
  Log.i(getClass().getSimpleName(), "background task - start");

  Hashtable<String, String> map = new Hashtable<String, String>();
  map.put("key", "value");

  try {

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ObjectOutputStream oos = new ObjectOutputStream(baos);
    oos.writeObject(map);

    PostMethod post = HttpUtils.sendMonitoredPOSTRequest(ServletUri,
                                                         null,
                                                         new ByteBuffer(baos.toByteArray()),
                                                         null);
    ByteBuffer data = HttpUtils.getMonitoredResponse(null, post);

    ObjectInputStream ois = new ObjectInputStream(data.getInputStream());
    DataFromServlet =
        (Hashtable<String, Hashtable<String, String>>) ois.readObject();

    Log.i(getClass().getSimpleName(), "data size from servlet=" + data.toString());
    Log.i(getClass().getSimpleName(), "data hashtable from servlet=" + DataFromServlet.toString());

  }
  catch (Exception e) {
    StringWriter sw = new StringWriter();
    PrintWriter pw = new PrintWriter(sw);
    e.printStackTrace(pw);
    Log.e(getClass().getSimpleName(), sw.getBuffer().toString(), e);
  }

  Log.i(getClass().getSimpleName(), "background task - end");

  if (UI_UPDATE_LISTENER != null) {
    UI_UPDATE_LISTENER.updateUI(DataFromServlet);
  }
}

private void _shutdownService() {
  if (timer != null) timer.cancel();
  Log.i(getClass().getSimpleName(), "Timer stopped!!!");
}

}//end class MyService

*/